﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Insurance.ReadCard;

namespace Insurance.ReadCard
{
    public class ReadCardService
    {
        /// <summary>
        /// 读卡交易
        /// </summary>
        /// <returns></returns>
        /// 统一封装的读卡信息入口
        /// </summary>
        /// <returns></returns>
        public static CardFormat ReadIcCard()
        {
            CardFormat card = null;
            try
            {
                FrmReadType fic = new FrmReadType();
                fic.ShowDialog();
                if (fic.DialogResult == DialogResult.OK)
                {
                    switch (fic.ReadType)
                    {
                        case SysPublic.READ_TYPE_CITYCARD:
                            card = ReadCityCard(); break;
                        case SysPublic.READ_TYPE_YBDZPZ:
                            card = ReadDzpzCard(); break;
                        case SysPublic.READ_TYPE_VITUAL:
                            card = ReadVirtualCard(); break;
                        case SysPublic.READ_TYPE_HEALTHCARD:
                            card = ReadHealthCard(); break;
                        case SysPublic.READ_TYPE_FACE:
                            card = ReadFace(fic.InputStr); break;
                        default:
                            card = null;
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("读卡失败" + ex.Message, "读卡失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return card;
        }

        /// <summary>
        /// 读取市民卡实体卡
        /// </summary>
        /// <returns></returns>
        public static CardFormat ReadCityCard()
        {
            CardReader cardReader = new CardReader();
            CardFormat cardFormat = cardReader.ReadIC(SysPublic.READER_TYPE);
            cardFormat.ReadType = SysPublic.READ_TYPE_CITYCARD;
            return cardFormat;
        }

        public static CardFormat ReadHealthCard()
        {
            return null;
        }

        public static CardFormat ReadFace(string inputStr)
        {
            return null;
        }

        public static CardFormat ReadDzpzCard()
        {
            CardFormat card = PublicRead.Get_HZYTH_全部信息_扫电子凭证();
            card.KaLeiBie = SysPublic.READ_TYPE_VITUAL;
            card.ReadType = SysPublic.READ_TYPE_YBDZPZ;
            return card;
        }

        /// <summary>
        /// 读取虚拟卡信息
        /// </summary>
        /// <returns></returns>
        public static CardFormat ReadVirtualCard()
        {
            CardFormat card = PublicRead.Get_HZYTH_全部信息_扫码();
            card.KaLeiBie = SysPublic.READ_TYPE_VITUAL;
            card.ReadType = SysPublic.READ_TYPE_VITUAL;
            return card;
        }
    }
}